#ifndef ROUTEMANAGERDIALOG_H
#define ROUTEMANAGERDIALOG_H

#include <QDialog>
#include <QTableWidget>
#include <QPushButton>
#include <QTabWidget>
#include <QLabel>
#include <QComboBox>
#include <QLineEdit>
#include <QList>

#define POLICY_ROUTE_CONF "/etc/btwise-policy-routes.conf"
#define POLICY_ROUTE_DISPATCHER "/etc/NetworkManager/dispatcher.d/99-btwise-policy-routes"

struct RouteEntry {
    QString destination; // 目标网络 192.168.1.0/24
    QString gateway;     // 网关
    QString iface;       // 出接口
    int metric;          // 跃点数
    QString type;        // 路由类型（永久/临时）
};

class RouteManagerDialog : public QDialog {
    Q_OBJECT
public:
    explicit RouteManagerDialog(QWidget *parent = nullptr);
private slots:
    void onAddRoute();
    void onEditRoute();
    void onDeleteRoute();
    void onRefresh();
private:
    void setupUi();
    void loadRoutes();
    void saveRoute(const RouteEntry &entry, bool isEdit, int row = -1);
    bool validateRoute(const RouteEntry &entry, QString &errMsg, int skipRow = -1) const;
    QTabWidget *tabWidget;
    QTableWidget *routeTable;
    QPushButton *btnAdd;
    QPushButton *btnEdit;
    QPushButton *btnDelete;
    QPushButton *btnRefresh;
    QLabel *envTipLabel;
    QList<RouteEntry> routeList;
};

#endif // ROUTEMANAGERDIALOG_H 